/*
动态规划求解：
dp[i][j]为到达点(i, j)的路线数目
由于只能往下或往右走
递推式:
dp[i][j] = dp[i-1][j] + dp[i][j-1]
初始情形:
dp[i][0] = dp[0][j] = 1

此外排列组合的方法也可以用来求解
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;

class Solution {
public:
    int uniquePaths(int m, int n)
    {
        if (m == 0 || n == 0)
            return 0;
        //initial
        long long dp[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 || j == 0)
                    dp[i][j] = 1;
                else
                    dp[i][j] = 0;
            }
        }
        //dp
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++)
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        }
        return dp[m - 1][n - 1];
    }
};

int main(int argc, char const* argv[])
{
    Solution temp;
    cout << temp.uniquePaths(7, 3) << endl;
    cout << temp.uniquePaths(3, 2) << endl;
    return 0;
}